package com.rico.deploy.service.impl;

import com.github.pagehelper.PageHelper;
import com.rico.deploy.entity.Major;
import com.rico.deploy.mapper.MajorMapper;
import com.rico.deploy.service.MajorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @author 夏智力
 * @FileName MajorService
 * @date 2021/5/2 17:49
 * @Software: IntelliJ IDEA
 */
@Service
public class MajorServiceImpl implements MajorService {
    @Autowired
    private MajorMapper majorMapper;

    @Override
    public List<Major> selectMajorByCollegeName(String collegeName) {
        Example example = new Example(Major.class);
        example.createCriteria()
                .andEqualTo("collegeName",collegeName);
        return majorMapper.selectByExample(example);
    }

    @Override
    public List<Major> selectAll(Integer page,Integer limit) {
        PageHelper.startPage(page,limit);
        return majorMapper.selectAll();
    }

    @Override
    public Major selectById(Integer id) {
        return majorMapper.selectByPrimaryKey(id);
    }

    @Override
    public int insertMajor(Major major) {
        return majorMapper.insert(major);
    }

    @Override
    public int deleteMajorById(Integer id) {
        return majorMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateMajor(Major major) {
        return majorMapper.updateByPrimaryKey(major);
    }
}
